from wrapper import *
from v8_ops import *
from selenium.webdriver.support.wait import WebDriverWait
import time
from retry import retry


@retry(tries=2, delay=2)
def click_city(driver):
    if isElementExist(driver, '//*[@id="changeCityBox"]'):
        driver.find_element_by_xpath('//*[@id="changeCityBox"]/ul/li[7]/a').click()
    else:
        raise


@retry(tries=2, delay=2)
def input_login(driver):
    if isElementExist(driver, '//*[@id="lg_tbar"]/div/div[2]/div/a[1]'):
        driver.find_element_by_xpath('//*[@id="lg_tbar"]/div/div[2]/div/a[1]').click()

        time.sleep(1)

        WebDriverWait(driver, 10).until(lambda x: x.find_element(By.XPATH,
                                                                 '/html/body/div[2]/div[1]/div/div/div[2]/div[3]/div[1]/div/div[1]/form/div[1]/input')).send_keys(
            "15018465953")

        WebDriverWait(driver, 10).until(lambda x: x.find_element(By.XPATH,
                                                                 '/html/body/div[2]/div[1]/div/div/div[2]/div[3]/div[1]/div/div[1]/form/div[2]/input')).send_keys(
            "a49810712a123")

        WebDriverWait(driver, 10).until(lambda x: x.find_element(By.XPATH,
                                                                 '/html/body/div[2]/div[1]/div/div/div[2]/div[3]/div[2]/div[2]/div[2]')).click()
    else:
        raise


def service():
    with keep_driver() as driver:
        driver.get(
            "https://www.lagou.com/jobs/list_Java?px=new&gm=150-500%E4%BA%BA,500-2000%E4%BA%BA,2000%E4%BA%BA%E4%BB%A5%E4%B8%8A&city=%E6%88%90%E9%83%BD#filterBox")

        # click_city(driver)
        # input_login(driver)


if __name__ == '__main__':
    service()
